<?php

use Illuminate\Support\Arr;

abstract class TestCase extends Laravel\Lumen\Testing\TestCase
{
    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        return require __DIR__ . '/../bootstrap/app.php';
    }

    public function getValue($key)
    {
        $resp = $this->response->getOriginalContent();
        return Arr::get($resp, $key);
    }

    /**
     * 获取token
     * @return array
     */
    public function getToken()
    {
        $body = [
            'username' => 'admin',
            'password' => '123456',
        ];
        // Success
        $this->json('POST', '/auth/login', $body)// 构造api请求
        ->seeStatusCode(200)// 判断返回状态
        ->seeJsonStructure([                  // 判断返回结构
            'code',
            'data' => [
                'user',
                'token',
            ],
        ]);
        $token = $this->getValue('data.token');
        $result = ['Authorization' => 'Bearer' . $token];
        return $result;
    }

}
